package day04;

import java.util.Scanner;

public class Exercise04 {
    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
        System.out.println("输入你的手机号");
//        String tel = sc.nextLine();
        for (; ; ) {
            String tel = new Scanner(System.in).nextLine();
            int price = getPrice(tel);
            if (price == -1) {
                System.out.println("格式不对，请重新输入");
            } else {
                System.out.println("您的尾号为" + tel.charAt(10) + "，应付费" + price + "元");
                break;
            }
        }
    }

    public static int getPrice(String tel) {
        if (tel.length() != 11) {//检查位数
            return -1;
        }
        for (int i = 0; i < 11; i++) {//检查输入数据是否为数字
            if (tel.charAt(i) < 48 || tel.charAt(i) > 57)
                return -1;
        }

        switch (tel.charAt(10)) {//char型
            case '8':
                return 50;
            case '4':
                return 0;
            default:
                return 20;
        }
    }
}
